package com.mike.gateway.adminapi;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class GatewayServiceApplication {

    /**
     * spring cloud gateway 配置方式之一，启动主程序配置，还有一种是配置文件配置
     * @param builder
     * @return
     */
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route(r -> r.path("/qq/**")
                        .and()
                        .uri("http://www.qq.com/"))
                .build();
    }

//    @Bean
//    public RouteLocator authFilter(RouteLocatorBuilder builder) {
//        return builder.routes().route(r ->
//                r.path("/user/list")
//                        .uri("http://localhost:8077/api/user/list")
//                        .filters(new AuthorizeGatewayFilter())
//                        .id("user-service"))
//                .build();
//    }
//
//    @Bean
//    public RouteLocator logFilter(RouteLocatorBuilder builder) {
//        return builder.routes().route(r ->
//                r.path("/user/list")
//                        .uri("http://localhost:8077/api/user/list")
//                        .filters(new AuthorizeGatewayFilter())
//                        .id("user-service"))
//                .build();
//    }

    public static void main(String[] args) {
        SpringApplication.run(GatewayServiceApplication.class, args);
    }
}